<template>
<h2>排房设置</h2>
<table class="table table-bordered">
    <tr>
        <td>房间类型</td>
        <td>
            <select v-model="info.type_id">
                <option :value="0">--请选择--</option>
                <option v-for="item in tinfo" :value="item.typeid">{{ item.typename }}</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>房间号码</td>
        <td>
            <select v-model="info.num_id">
                <option :value="0">--请选择--</option>
                <option v-for="item in ninfo" :value="item.numid">{{ item.numname }}</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>房间状态</td>
        <td>
            <input type="radio" :value="true" v-model="info.ostate"/>启用
            <input type="radio" :value="false" v-model="info.ostate"/>禁用
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <button @click="Add" class="btn btn-info">提交</button>
        </td>
    </tr>
</table>
</template>


<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router';
const router=useRouter()

const tinfo=ref([{
    typeid:0,
    typename:''
}])
const ninfo=ref([{
    numid:0,
    numname:''
}])
onMounted(()=>{
    axios.get('https://localhost:7173/api/Room/GetRoomTypes')
    .then(res=>{
        tinfo.value=res.data
    })
    axios.get('https://localhost:7173/api/Room/GetRoomNums')
    .then(res=>{
        ninfo.value=res.data
    })
})
const info=ref({
    type_id:0,
    num_id:0,
    ostate:true
})

const Add=()=>{
    axios.post('https://localhost:7173/api/Room/RoomOrderAdd',{
        type_id:info.value.type_id,
        num_id:info.value.num_id,
        ostate:info.value.ostate
    })
    .then(res=>{
        if(res.data==-1){
            alert('该房号已被排房')
        }
        else if(res.data>0){
            alert('设置成功')
            router.push('/RoomTypeShow')
        }
        else{
            alert('设置失败')
        }
    })
    .catch(err=>{
        console.log(err)
    })
}


</script>